import pandas as pd
from sentensDB import sentensDB
import config
class wordsTable:
    csv_path = ''
    df = None
    def __init__(self, path='../resource/english.csv'):
        self.csv_path = path
        self.df = pd.read_csv(self.csv_path)
    def read_unmach_word(self):
        unmach_idx = [index for index,val in self.df['state'].items() if val == 0] #list
        unmach_word = [(idx, val) for idx,val in self.df['word'][unmach_idx].items()] #List [(idx, word)]
        return unmach_word
    def update(self):
        unmach_word = self.read_unmach_word()
        stens_db = sentensDB(path=config.sentence_db_path)
        for x in unmach_word:
            sentens = stens_db.get_sentens(x[1])
            self.df.loc[x[0]:x[0], 'sentence'] = sentens
            # self.df.loc[x[0]:x[0], 'state'] = 1
        self.df.to_csv(self.csv_path,index=False)
